var app = getApp()
var util = require("../../utils/util.js")
var tuiModel = require("../../model/tuiModel.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance: 0,
    name: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      balance: options.balance,
      name: app.data.user.name
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  inputMoney(e) {
    var money = e.detail.value
    this.setData({
      money: money
    })
  },
  bindApply(){
    var money=this.data.money
    if (!/^(\d+|\d+\.\d{1,2})$/.test(money)) {
      util.failToast("金额有误")
      return
    }
    var that=this
    tuiModel.rewardApply(money,res=>{
      if(res.status==1){
        util.failToast(res.msg)
        return
      }
      var m=that.data.balance-money
      wx.showModal({
        content: '提现申请提交成功,等待审核',
        showCancel:false
      })
      that.setData({
        balance:parseFloat(m.toFixed(2))
      })
    })
  }
})